package com.ymatou.iapi.trading.operate.service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

/**
 * 创建订单(新)接口Call FreeMaker Template自动生成代码
 */
public class PlaceOrderCall extends YmatouBaseCall {
	private static String opurl = "placeorder/placeorder";

	public PlaceOrderCall() {
		super(EnvSetup.getSystemUrl("operate_iapi"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	// get data
	public JSONObject getData() {
		JSONObject data = null;
		try {
			data = (JSONObject) new JSONObject(getReturnData()).get("data");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}

	// get orderids
	public JSONArray getOrderIds() {
		JSONArray ordersArray = null;
		try {
			ordersArray = getData().getJSONArray("orderIds");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ordersArray;
	}
	// tradeId
	public int getCode() {
		Integer code = null;
		try {
			code = new JSONObject(getReturnData()).getInt("code");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return code;
	}
	// tradeId
	public int getTradingId() {
		Integer tradingId = null;
		try {
			tradingId = getData().getInt("tradeId");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tradingId;
	}

	// mainOrderId
	public int getMainOrderId() {
		Integer mainOrderId = null;
		try {
			mainOrderId = getData().getInt("mainOrderId");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return mainOrderId;
	}
}
